﻿namespace Filters
{

    /// <summary>
    /// 日志中间件
    /// </summary>
    public class SseMiddleware
    {
        private readonly RequestDelegate _next;

        public SseMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task InvokeAsync(HttpContext context)
        {

            if (context.Request.Path.StartsWithSegments("/mcp/sse")) //只判断sse请求
            {
                string token = context.Request.Query["key"];   //使用heard 还是query 取token自行修改
                if (token != "123456")  //token校验 自行修改
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("无权限");

                    return;
                }

            }

            await _next(context);

        
        }




    }
}
